class PotatoMine extends GuaAnimation {
    static new(game) {
        let p = new this(game, animationPotatoMine)
        p.setup()
        return p
    }

    setup() {
        // row表示在草地的第几排
        this.row = -1
        this.cooldown = 200
        this.score = 25
        this.exit = 20
        this.hp = 50
        this.ready = false
        this.boom = false
    }

    remove() {
        if (this.boom) {
            this.exit--
            if (this.exit === 1) {
                this.scene.removeElement(this.mashed)
            }
            if (this.exit === 0) {
                this.scene.removePotatoMine(this)
            }
        }
    }

    explosion() {
        this.changeAnimation('explosion')
        let mashed = GuaImage.new(this.game, 'mashed')
        mashed.x = this.x
        mashed.y = this.y - 20
        this.mashed = mashed
        this.scene.addElement(mashed)
    }

    notready() {
        this.changeAnimation('notready')
    }

    idle() {
        this.changeAnimation('idle')
    }

    changestatus() {
        this.cooldown--
        if (this.cooldown === 0) {
            this.idle()
            this.ready = true
        }

    }

    booming() {
        this.explosion()
        this.boom = true
    }

    attack() {
        this.hp--
        if (this.hp === 0) {
            this.scene.removePotatoMine(this)
        }
    }

    update() {
        super.update()
        this.changestatus()
        this.remove()
        // this.cracked()
    }
}